package com.xiangban.util;

import com.github.wxpay.sdk.WXPayConfig;
import lombok.Data;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

@Data
public class WXConfigUtil implements WXPayConfig {

    public String APP_ID ;
    public String APP_KEY ;
    public String MCH_ID ;
    public String CERT_PATH;
   public static final String PATH = "/opt/xiangban_doctor/doctor_mobile/cert/apiclient_cert.p12";
//    public static final String PATH_LOCAL = "C:\\apiclient_cert.p12";

    private final byte[] certData;
    public WXConfigUtil() throws Exception {
        File file = new File(PATH);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }


    @Override
    public String getAppID() {
        return APP_ID;
    }

    @Override
    public String getMchID() {
        return MCH_ID;
    }

    @Override
    public String getKey() {
        return APP_KEY;
    }


    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;

    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
